<?php
/**
 * Joomla! 1.5 component ArticleCashRewards
 *
 * @version $Id: cpanel.php 2009-05-10 01:47:01 svn $
 * @author Maverick
 * @package models
 * @subpackage ArticleCashRewards
 * @license GNU/GPL
 * Website: http://www.boddunan.com
 *
 * Review and approve the articles and assign points and cash rewards.
 * Users can see their articles and the points/cash rewards assigned in the front-end module.
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');

if(!class_exists('ContentHelperRoute')) require_once (JPATH_SITE . '/components/com_content/helpers/route.php');

class ArticleCashRewardsModelCpanel extends JModel {

	function __construct(){

		parent::__construct();
	}

    function getApprovedArticles() {
	    
    	global $mainframe, $option;
    	
    	// Get a database object
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();

		$query = 'SELECT a.id, a.alias, a.title, a.sectionid, a.catid, s.title AS section, cc.title AS category,'.
			' s.access AS sec_access, cc.access AS cat_access, s.published AS sec_state, cc.published AS cat_state,'.
			' u.username AS author, a.created_by_alias, a.created_by, acr.points, acr.cash, acr.remarks,' .
			' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
			' CASE WHEN CHAR_LENGTH(cc.title) THEN CONCAT_WS(":", cc.id, cc.title) ELSE cc.id END as catslug'.
			' FROM #__content AS a' .
			' LEFT JOIN #__categories AS cc ON cc.id = a.catid' .
			' LEFT JOIN #__sections AS s ON s.id = a.sectionid' .
			' LEFT JOIN #__users AS u ON u.id = a.created_by' .
			' LEFT JOIN ' . TABLE_ACR_CONTENT  . ' AS acr ON acr.article_id = a.id' .
			' WHERE a.state = 1 AND acr.status = 1 ORDER BY a.created DESC';
//echo $query;

		$db->setQuery($query, 0, 5);
		$rows = $db->loadObjectList();

		return $rows;
    }

    function getPendingArticles() {

    	global $mainframe, $option;
    	// Get a database object
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();

		$query = 'SELECT a.id, a.alias, a.title, a.sectionid, a.catid, s.title AS section, cc.title AS category,'.
			' s.access AS sec_access, cc.access AS cat_access, s.published AS sec_state, cc.published AS cat_state,'.
			' u.username AS author, a.created_by_alias, a.created_by,' .
			' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
			' CASE WHEN CHAR_LENGTH(cc.title) THEN CONCAT_WS(":", cc.id, cc.title) ELSE cc.id END as catslug'.
			' FROM #__content AS a' .
			' LEFT JOIN #__categories AS cc ON cc.id = a.catid' .
			' LEFT JOIN #__sections AS s ON s.id = a.sectionid' .
			' LEFT JOIN #__users AS u ON u.id = a.created_by' .
			' LEFT JOIN ' . TABLE_ACR_CONTENT  . ' AS acr ON acr.article_id = a.id' .
			' WHERE acr.status=0 OR acr.status IS NULL';
//echo $query;
		$db->setQuery($query, 0, 5);
		$rows = $db->loadObjectList();

		return $rows;
    }

    function getRejectedArticles() {

    	global $mainframe, $option;

    	// Get a database object
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();

		$query = 'SELECT a.id, a.alias, a.title, a.sectionid, a.catid, s.title AS section, cc.title AS category,'.
			' s.access AS sec_access, cc.access AS cat_access, s.published AS sec_state, cc.published AS cat_state,'.
			' u.username AS author, a.created_by_alias, a.created_by, acr.points, acr.cash, acr.remarks,' .
			' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
			' CASE WHEN CHAR_LENGTH(cc.title) THEN CONCAT_WS(":", cc.id, cc.title) ELSE cc.id END as catslug'.
			' FROM #__content AS a' .
			' LEFT JOIN #__categories AS cc ON cc.id = a.catid' .
			' LEFT JOIN #__sections AS s ON s.id = a.sectionid' .
			' LEFT JOIN #__users AS u ON u.id = a.created_by' .
			' LEFT JOIN ' . TABLE_ACR_CONTENT  . ' AS acr ON acr.article_id = a.id' .
			' WHERE a.state = 0 AND acr.status = 2 ORDER BY a.created DESC';
//echo $query;

		$db->setQuery($query, 0, 5);
		$rows = $db->loadObjectList();

		return $rows;
    }
}
?>